package com.objectcarpentry.kaylee.ui.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.command.DeleteCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import com.objectcarpentry.kaylee.KayleePlugin;

public class DeleteHandler extends AbstractHandler {

	
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		ISelection sel = HandlerUtil.getCurrentSelection(event);
		if (sel != null && sel instanceof IStructuredSelection) {
			EditingDomain domain = KayleePlugin.getDefault().getEditingDomain();
			IStructuredSelection ssel = (IStructuredSelection) sel;
			Command command = DeleteCommand.create(domain, ssel.toList());
			domain.getCommandStack().execute(command);
		}
		return null;
	}

}
